﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Diagnostics;
using System.Xml.Serialization;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Collections;
using geoqualMenuBar;

public partial class _Default : Page
{
    idofMenu MenuName = idofMenu.None;
    private enum idofMenu
    {
        Administración_de_Solicitudes,
        Por_Nombre,
        Por_Apellido,
        Por_Dirección,
        Por_Calle,
        Por_Ciudad,
        Por_Solicitud,
        Tareas_Autorizadores,
        Desarrolladores,
        Eliminar_Tareas,
        Basico,
        Avanzado,
        What_if,
        Analizar,
        None
    }

    private enum textofMenu
    {
        Enquiries,
        By_Name,
        By_Surname,
        By_Address,
        By_Street,
        By_City,
        By_Petition,
        Authorized_Tasks,
        Developers,
        Delete_Tasks,
        Basic,
        Advanced,
        What_if,
        Analysis
    }

    protected MenuBars m = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        GQMenuBar1.Command += new CommandEventHandler(GQMenuBar1_Command);
        GQMenuBar1.Height = 25;
        GQMenuBar1.Width = 140;
        GQMenuBar1.Fontfamily = "Arial, " + GQMenuBar1.Fontfamily;

        //now load a control on the main panel
        System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
        img.ImageUrl = "images/gqDownHover.gif";

        //Levels 4
        MenuBars fo = new MenuBars();
        MenuBarItem itemwithIcon = new MenuBarItem(idofMenu.What_if.ToString(), textofMenu.What_if.ToString());
        itemwithIcon.Icon = img;

        fo.Add(itemwithIcon);
        fo.Add(new MenuBarItem(idofMenu.Analizar.ToString(), textofMenu.Analysis.ToString()));

        //Levels 3
        MenuBars ba = new MenuBars();
        ba.Add(new MenuBarItem(idofMenu.Basico.ToString(), textofMenu.Basic.ToString(), 200));
        ba.Add(new MenuBarItem(idofMenu.Avanzado.ToString(), textofMenu.Advanced.ToString(), fo));

        MenuBars cc = new MenuBars();
        cc.Add(new MenuBarItem(idofMenu.Por_Calle.ToString(), textofMenu.By_Street.ToString().Replace("_", " ")));
        cc.Add(new MenuBarItem(idofMenu.Por_Ciudad.ToString(), textofMenu.By_City.ToString().Replace("_", " ")));

        //Levels 2
        MenuBars pp = new MenuBars();
        pp.Add(new MenuBarItem(idofMenu.Por_Nombre.ToString(), textofMenu.By_Name.ToString().Replace("_", " "), "This has to be done by name"));
        pp.Add(new MenuBarItem(idofMenu.Por_Apellido.ToString(), textofMenu.By_Surname.ToString().Replace("_", " ")));
        pp.Add(new MenuBarItem(idofMenu.Por_Dirección.ToString(), textofMenu.By_Address.ToString().Replace("_", " "), cc));
        pp.Add(new MenuBarItem(idofMenu.Por_Solicitud.ToString(), textofMenu.By_Petition.ToString().Replace("_", " ")));

        MenuBars et = new MenuBars();
        et.Add(new MenuBarItem(idofMenu.Eliminar_Tareas.ToString(), textofMenu.Delete_Tasks.ToString().Replace("_", " "), ba));

        //Levels 
        MenuBars lo = new MenuBars();
        lo.Add(new MenuBarItem(idofMenu.Administración_de_Solicitudes.ToString(), textofMenu.Enquiries.ToString().Replace("_", " "), pp));
        MenuBarItem itmwithIcon = new MenuBarItem(idofMenu.Tareas_Autorizadores.ToString(), textofMenu.Authorized_Tasks.ToString().Replace("_", " "));
        itmwithIcon.Icon = img;
        lo.Add(itmwithIcon);
        lo.Add(new MenuBarItem(idofMenu.Desarrolladores.ToString(), textofMenu.Developers.ToString().Replace("_", " "), et));


        m = new MenuBars();
        m.Add(new MenuBarItem(lo));

        GQMenuBar1.SetMenuBar(m);
        GQMenuBar1.DataBind();

        //**************************** Second MenuBar created from Xml *****************

        //load the 2nd menubar
        GQMenuBar2.Command += new CommandEventHandler(GQMenuBar1_Command);
        GQMenuBar2.FontSize = 14;
        GQMenuBar2.Color = Color.LightYellow;
        GQMenuBar2.SelectedColor = Color.Moccasin;
        GQMenuBar2.BackColor = Color.White;
        GQMenuBar2.BackColor2 = Color.Green;
        GQMenuBar2.SelectedBackgroundColor = Color.LightGray;
        GQMenuBar2.SelectedBackgroundColor2 = Color.Black;
        GQMenuBar2.HoverBackgroundColor = Color.LightCyan;
        GQMenuBar2.HoverBackgroundColor2 = Color.DarkCyan;
        GQMenuBar2.NavMenuXML = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "XMLFile.xml");
        GQMenuBar2.DataBind();
    }

    private void GQMenuBar1_Command(object sender, CommandEventArgs e)
    {
        Debug.Print("Command event received from " + ((WebControl)sender).ID);
        Debug.Print("Command arg received from " + e.CommandName);
        Debug.Print("Command arg received from " + e.CommandArgument);
        string menubarclicked = e.CommandName.Replace("btn", string.Empty);
        MenuName = (idofMenu)Enum.Parse(typeof(idofMenu), menubarclicked, true);
        string alert = "alert('{0}')";
        alert = string.Format(alert, MenuName.ToString());
        if (MenuName != idofMenu.None) showAlert(alert);
    }

    private void showAlert(string alert) {
        if (!ClientScript.IsStartupScriptRegistered("jsalert" + alert)) {
            ClientScript.RegisterStartupScript(this.GetType(), "jsalert" + alert, alert, true);
        }
    }
}